/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package com.lovetemperature.model.test;

import java.util.Locale.Category;

import javax.persistence.CascadeType;

import junit.framework.TestCase;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.lovetemperature.model.Good;
import com.lovetemperature.model.GoodCategory;

/**
 * Illustrates use of Hibernate native APIs.
 * 
 * @author Steve Ebersole
 */
public class AddGood extends TestCase {
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("deprecation")
	@Override
	protected void setUp() throws Exception {
		sessionFactory = new Configuration().configure().buildSessionFactory();
	}

	@Override
	protected void tearDown() throws Exception {
		if (sessionFactory != null) {
			sessionFactory.close();
		}
	}

	public void testBasicUsage() {
		//添加蛋糕
//		addGood(10,"http://mall.christine.com.cn/images/goods/20130301/412d73eb0a8ecc5f.jpg","窝窝团团购 经典巧克力慕斯",78.00);
//		addGood(20,"http://mall.christine.com.cn/images/goods/20130128/e9dc9f7d8af5160c.jpg","全网特供精品蛋糕 抹茶情深",138.00);
//		addGood(11,"http://mall.christine.com.cn/images/goods/20130128/61f5f1157554aae3.jpg","全网特供精品蛋糕 巧杏斯",188.00);
//		addGood(15,"http://mall.christine.com.cn/images/goods/20130128/9db3d4b2ea8f41e8.jpg","全网特供精品蛋糕 夏忆香芒",188.00);
//		addGood(12,"http://mall.christine.com.cn/images/goods/20130128/e366bd18535ea917.jpg","全网特供精品蛋糕 雪域天使",138.00);
//		addGood(11,"http://mall.christine.com.cn/images/goods/20120801/09bc85c554d53164.jpg","婚礼蛋糕永结同心",694.00);
//		addGood(12,"http://mall.christine.com.cn/images/goods/20120509/2f617f4276011ad1.jpg","甜蜜恋人旗舰店专供 法式栗子",138.00);
//		addGood(14,"http://mall.christine.com.cn/images/goods/20120509/cd21e4cfe120e511.jpg","旗舰店专供蛋糕 甜蜜蜜",148.00);
//		addGood(16,"http://mall.christine.com.cn/images/goods/20120509/0b13b8dc4b894a2f.jpg","甜蜜恋人旗舰店专供 经典布朗尼",168.00);
//		addGood(18,"http://mall.christine.com.cn/images/goods/20120606/311b97074ef8ad12.jpg","甜蜜旗舰店专供蛋糕 皇冠",158.00);
		//添加面包
//		addGood(12, "http://mall.christine.com.cn/images/goods/20120518/f9ec5c27b59ce609.jpg", "GABA调理法包（蒜香）", 150.00);
//		addGood(19, "http://mall.christine.com.cn/images/goods/20120518/6b07eb91a7c8afc6.jpg", "GABA披萨杂粮法包（咖喱味）", 320.00);
//		addGood(22, "http://mall.christine.com.cn/images/goods/20120518/6907430c3714ae8c.jpg", "GABA披萨法包（蒜香培根）", 320.00);
//		addGood(12, "http://mall.christine.com.cn/images/goods/20120518/84c315a650963b07.jpg", "GABA披萨杂粮法包（黑胡椒培根）", 320.00);
//		addGood(14, "http://mall.christine.com.cn/images/goods/20120518/f0b727a7f1fb67c0.jpg", "GABA调理杂粮法包（香辣）", 150.00);
//		addGood(11, "http://mall.christine.com.cn/images/goods/20120419/3962c40b12617eff.jpg", "面包组合C--满额免费配送", 510.00);
		//添加干点
//		addGood(10, "http://mall.christine.com.cn/images/goods/20130311/d962f3a2adeb9084.jpg", "萝玛盾牌 甜蜜恋人手工饼干", 12.00);
//		addGood(20, "http://mall.christine.com.cn/images/goods/20130311/be19087119b25044.jpg", "玛琍酥 甜蜜恋人手工饼干", 12.00);
//		addGood(21, "http://mall.christine.com.cn/images/goods/20130311/1e47fc40031ecec2.jpg", "奶香曲奇 甜蜜恋人手工饼干", 12.00);
//		addGood(22, "http://mall.christine.com.cn/images/goods/20130311/598790d03b19879a.jpg", "大理石 甜蜜恋人手工饼干", 15.00);
//		addGood(100, "http://mall.christine.com.cn/images/goods/20121206/ccb2f697e94c1584.jpg", "可口脆", 30.00	);
//		addGood(10, "http://mall.christine.com.cn/images/goods/20120408/3980e5cb541b023b.jpg", "花生球", 8.50);
//		addGood(10, "http://mall.christine.com.cn/images/goods/20120408/31b81f2c26b68d07.jpg", "凤梨酥家庭装", 10.00);
		//添加拌手礼
//		addGood(20, "http://mall.christine.com.cn/images/goods/20120815/62b4061fa4c519b4.jpg", "小蝴蝶结礼盒A", 76.3);
//		addGood(20, "http://mall.christine.com.cn/images/goods/20120815/f4900f49c4395a22.jpg", "中蝴蝶结礼盒", 132.2);
//		addGood(20, "http://mall.christine.com.cn/images/goods/20120408/92c57f9b7b14b350.jpg", "蟹派大礼盒", 38.0);
//		addGood(100, "http://mall.christine.com.cn/images/goods/20130311/281e71e1d5adf855.jpg", "清明伴手礼预售 春意阑珊（抹茶酥）", 25.00);
		//添加饮品
//		addGood(100, "http://mall.christine.com.cn/images/goods/20120409/440bcdbec6e9ea2c.jpg", "拿铁咖啡(铁罐装)", 5.9);
//		addGood(100, "http://mall.christine.com.cn/images/goods/20120409/66665649d941b3fa.jpg", "经典咖啡(铁罐装)", 5.9);
//		addGood(100, "http://mall.christine.com.cn/images/goods/20120409/bf800ae3eff64a78.jpg", "100%精选苹果汁", 7.9);
//		addGood(100, "http://mall.christine.com.cn/images/goods/20120409/b84b81cd84e1ce6e.jpg", "100%精选橙汁", 7.9);
//		addGood(100, "http://mall.christine.com.cn/images/goods/20120409/985be7420c6325a2.jpg", "100%精选果汁组合", 36.0);
		//添加其他
		addGood(100, "http://mall.christine.com.cn/images/goods/20120713/1c9ec2628d46dece.jpg", "蒟蒻小果冻(蓝莓)", 6.8);
		addGood(100, "http://mall.christine.com.cn/images/goods/20120409/39bb64d46a50b55d.jpg", "花生牛轧糖", 28.00);
		addGood(100, "http://mall.christine.com.cn/images/goods/20120409/12f2aec88eb11276.jpg", "立式蒟蒻果冻菠萝", 5.8);
	}
	
	private void addGood(int count, String img, String name, double price){
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		
		Good g1 = new Good();
		g1.setCategory(GoodCategory.其他);
		g1.setImage(img);
		g1.setName(name);
		g1.setPrice(price);
		g1.setSalePrice(50.00);
		
		session.save(g1);

		session.getTransaction().commit();
		session.flush();
		session.close();
	}
}
